package com.example.exam_demo.controller;


import com.example.exam_demo.model.Information;
import com.example.exam_demo.service.InformationService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


import java.util.List;

@RestController
@Api("用户管理")
public class InformationController {
    @Autowired
    InformationService informationService;

    @GetMapping("/informations")
    public List<Information> getAllStudents(){
        return informationService.list();
    }

    @GetMapping("/information/{id}")
    public Information getStudentById(@PathVariable("id") Integer id){
        return informationService.getById(id);

    }

    @PostMapping("/information")
    public String addStudent(@RequestBody Information information){
        if (informationService.save(information)){
            return "添加成功";
        }else return "添加失败";
    }

    @DeleteMapping("/information/{id}")
    public String deleteStudentById(@PathVariable("id") Integer id){
        if (informationService.removeById(id)){
            return "删除成功";
        }else return "删除失败";
    }

    @RequestMapping("/information")
    public String updateStudent(@RequestBody Information information){
        if (informationService.updateById(information)){
            return "修改成功";
        }else return "修改失败";
    }
}
